package com.codedef.controller;

import com.codedef.common.response.Result;
import com.codedef.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    UserService userService;



    /**
     * 获取当前登录用户的个人信息
     */
    @GetMapping("/userInfo")
    public Result getCurrentUserInfo(@RequestHeader("USER_ID") String userId) {
        return Result.SUCCESS(userService.getCurrentUserInfo(Integer.parseInt(userId)));
    }


    /* --------------------------------- Feign接口 --------------------------------- */
    /**
     * 将某个用户的预约次数加1
     */
    @GetMapping("/f/incrReservationNum/{userId}")
    public String increaseReservationNumberFeign(@PathVariable("userId") Integer userId) {
        userService.increaseReservationNumber(userId);
        return "SUCCESS";
    }

    /**
     * 将用户的违约次数+1
     * @param userId 用户的id
     */
    @GetMapping("/f/increaseDefaultNumber/{userId}")
    public String increaseDefaultNumber(@PathVariable("userId") Integer userId) {
        userService.increaseDefaultNumber(userId);
        return "SUCCESS";
    }

}
